import { Dimensions, Platform } from 'react-native';
import { getStatusBarHeight } from 'react-native-iphone-x-helper';

const window = Dimensions.get('window');
const DviceHeight = Dimensions.get('window').height;
const DviceWidth = Dimensions.get('window').width;
const ScreenWidth = Dimensions.get('screen').width;
const ScreenHeight = Dimensions.get('screen').height;
const DeviceHeight = Dimensions.get('window').height;
const DeviceWidth = Dimensions.get('window').width;
/**
 * StatusBar高度
 */
const statusBarHeight = getStatusBarHeight(true);
/**
 * 导航栏高度
 */
const navBarHeight = Platform.OS === 'ios' ? 44 : 44;
const realHeaderHeight = statusBarHeight + navBarHeight;

const px2dp: (px: number) => number = (px: number) => (px / 375) * window.width;
type opacity = 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1;
const palette = {
  transparent: `rgba(0,0,0,0)`,
  Main: (opacity: opacity = 1) => `rgba(234, 51, 35, ${opacity})`,
  ActiveMain: (opacity: opacity = 1) => `rgba(41, 142, 136, ${opacity})`,
  Danger: (opacity: opacity = 1) => `rgba(255, 61, 74, ${opacity})`,
  Warning: (opacity: opacity = 1) => `rgba(255, 187, 0, ${opacity})`,
  Info: (opacity: opacity = 1) => `rgba(0, 99, 247, ${opacity})`,
  Success: (opacity: opacity = 1) => `rgba(1, 208, 134, ${opacity})`,
  W: (opacity: opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
  G1: (opacity: opacity = 1) => `rgba(245, 247, 250, ${opacity})`,
  G2: (opacity: opacity = 1) => `rgba(225, 227, 229, ${opacity})`,
  G3: (opacity: opacity = 1) => `rgba(195, 197, 199, ${opacity})`,
  G4: (opacity: opacity = 1) => `rgba(157, 159, 163, ${opacity})`,
  G5: (opacity: opacity = 1) => `rgba(108, 110, 112, ${opacity})`,
  G6: (opacity: opacity = 1) => `rgba(39, 41, 46, ${opacity})`,
  G7: (opacity: opacity = 1) => `rgba(44, 45, 47, ${opacity})`,
  G8: (opacity: opacity = 1) => `rgba(23, 26, 31, ${opacity})`,
  B: (opacity: opacity = 1) => `rgba(0, 0, 0, ${opacity})`,
};
const secondToTime = (seconds: number): string => {
  const hour = Math.floor(seconds / 3600);
  const residualFromHour = seconds % 3600;
  const minute = `${Math.floor(residualFromHour / 60)}`.padStart(2, '0');
  const second = `${Math.floor(residualFromHour % 60)}`.padStart(2, '0');
  let output = `${minute}:${second}`;
  hour && (output = `${hour}:${output}`);
  return output;
};
const bin = (value: boolean): 0 | 1 => {
  'worklet';
  return value ? 1 : 0;
};

export {
  px2dp,
  DviceHeight,
  DviceWidth,
  palette,
  secondToTime,
  realHeaderHeight,
  bin,
  DeviceHeight,
  DeviceWidth,
  ScreenHeight,
  ScreenWidth,
};
